function new_section = update_section(M,first,last,fs,B) %new_section is a structure with index and wave, wave is a cell_struct,each beat a cell 
% tic
global info;
new_section.index = first:last;
new_section.delay = M(2,first:last); 
new_section.wave = [];
% if first == last
%     return;
% end
for k=first:last
    t = 0:1/fs:M(2,k);   %M(2,k) is the time it remain
    if M(1,k)~=0      % not a rest
        s=harmonic_func(info.instrument,M(1,k),t);  % add harmonics 
%         envelopedWave=envelope_func(info.instrument,info.env_mode ,t,s);
        envelopedWave=envelope_func(info.instrument,info.env_mode,t,s,B); % add envelope to wave
        new_section.wave = [new_section.wave envelopedWave];  % add wave to section
    else     % a rest
        new_section.wave = [new_section.wave zeros(1,length(t))];
    end
end
if info.equa == 1  % T_EQ
    new_section.wave = time_domain_equalizer(info.equa_C,info.fs,info.equa_N,new_section.wave); % operate the equalizer 
elseif info.equa == 2  % F_EQ
    new_section.wave = freq_EQ(info.equa_C,info.fs,info.section_len*info.l,new_section.wave);
end
% toc
% disp(toc);
end

